package org.pearl.mybatis.demo.test;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.pearl.mybatis.demo.dao.UserMapper;
import org.pearl.mybatis.demo.pojo.entity.User;
import org.pearl.mybatis.demo.pojo.qurey.UserQuery;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by TD on 2021/6/21
 */
public class CodeTest001 {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);


        SqlSession sqlSession = sqlSessionFactory.openSession();



        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        UserQuery userQuery = new UserQuery();
        userQuery.setLoginName("zhangwei");
        List<User> dynamicUserList = userMapper.selectDynamicUserList(userQuery);
        System.out.println(dynamicUserList);
        sqlSession.commit();
        sqlSession.close();
    }
}
